package com.zzt.controller;

import com.zzt.util.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
public class testRedisController {

    @Autowired
    RedisUtils redisUtils;

    private static int ExpireTime = 60;   // redis中存储的过期时间60s

    @RequestMapping("/testR")
    public void testR(){
        redisUtils.set("hi","hi");
    }

    @RequestMapping("/level/hi")
    public String level1(){
        return "views/level1/";
    }

    @RequestMapping("gets")
    public Object gets(){
        //获取上下栈
        SecurityContext context = SecurityContextHolder.getContext();
        Authentication authentication1 = context.getAuthentication();
        User principal = (User)authentication1.getPrincipal();
        System.out.println(principal.getUsername());
        return principal;
    }
}
